﻿using DotnetCore.Extension.DependencyInjection;
using Microsoft.Extensions.Configuration;
using MQTT.Server.App.Dto;
using MQTT.Share.ConfigurationExtension;
using System.Collections.Generic;

namespace MQTT.Server.App
{
    public class MqttServerHelper : ISingletonDependency
    {

        private IConfiguration Configuration { get; set; }
        public MqttServerHelper(IConfigurationManager configurationManager)
        {
            Configuration = configurationManager.Configuration;
        }

        public List<ClientDesc> GetClients()
        {

            List<ClientDesc> result = new List<ClientDesc>();
            var clientConfig = Configuration.GetSection("MQTT:Clients");
            var clients = clientConfig.GetChildren();
            foreach (var client in clients)
            {
                result.Add(new ClientDesc
                {
                    Type = client["type"],
                    Id = client["id"],
                    Password = client["password"]
                });
            }
            return result;
        }

    }
}
